<%-- 
    Document   : add_controller
    Created on : 2009-5-23, 23:05:19
    Author     : user
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*, java.io.*, java.util.*, database.*" %>
<%@ page import="creater.*" %>
<jsp:useBean id="con" class="database.DatabaseConnection"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        con.createConnection();
        String title = null;
        String content = null;
        String newsType = (String) session.getAttribute("newsType");


        if (!(request.getParameter("title").toString().isEmpty())) {
            System.out.println("sdsadasdasdsadasd");
            title = request.getParameter("title");
        }
        if (!(request.getParameter("content").toString().isEmpty())) {
            content = request.getParameter("content");
        }

        if (title != null) {
            if (content != null) {
                String rootPath = request.getRealPath("/");

                int size = (int) newsCreater.newsSizeByFolder(rootPath + "news\\newsbydate\\200905");
                size++;

                String address = rootPath + "news\\newsbydate\\200905\\" + "200905" + size + ".html";

                //System.out.println("sdsd"+title + content);
                newsCreater.insert(title, content, address, rootPath);


                int sequence = new Integer("200905" + size).intValue();
                con.insertNews("/news/newsbydate/200905/" + "200905" + size + ".html", title, newsType, sequence);

        %>

        <%=title%><br>
        <%=content%><br><br>
        It is allready store at <%=address%>
        <input align="center" type="button" value="back" onclick="window.history.back()">
        <%

            } else {
                out.println("<center>Please enter a correct content<br>");
                out.println("<input align=\"center\" type=\"button\" value=\"back\" onclick=\"window.history.back()\"></center>");
            }

        } else {
            out.println("<center>Please enter correct title<br>");
            out.println("<input align=\"center\" type=\"button\" value=\"back\" onclick=\"window.history.back()\"></center>");
        }
        %>
    </body>
</html>
